﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>


<form action="spiel_edit_v.php" method="post">

<table>

<?php

	include("../inc/joomlaInt_admin.php");
	include("../inc/inc_configuration.php");
	
if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{
	
	$q="SELECT gid FROM $tbl_users WHERE id=$jUser";
					$qe=mysql_query($q);
					$qeo=mysql_fetch_object($qe);
					
					$gid=$qeo->gid;
					
					if ($gid!=$admingroup)
					{
						echo "Du bist kein Admin!";
						break;
					}
					
	$match=$_GET["match"];
	$ref=$_GET["ref"];
	
	echo "<input type='text' name='matchId' hidden value='",$match,"'>";
	
	$q = "SELECT * FROM $tbl_matches WHERE id=$match";
	$qe = mysql_query($q);
	$qeo = mysql_fetch_object($qe);
	
	$matchday = $qeo->matchday;
	$liga = $qeo->leagueId;
	$stage = $qeo->stageId;
	$homeT = $qeo->homeT;
	$guestT = $qeo->guestT;
	$free = $qeo->free;
	
	echo "<input type='text' name='stage' hidden value='",$stage,"'>";
	
	$lq = "SELECT * FROM $tbl_lt WHERE leagueId=$liga";
	$lqe = mysql_query($lq);
	$lqc = mysql_num_rows($lqe);

	$mAnz = ($lqc-1)*2;
	
	echo'<tr>
			<td>Spieltag:</td>
			<td><select name="matchday" Size="1">';
	
	$count = 1;
	
	if ($ref==1)
	{
		echo '<Option selected Value="1">1</option>';
	}
	else
	{
		while($count < $mAnz+1)
		{
			$t="";
			if ($count==$matchday)
			{
				$t="selected";
			}
			echo '<Option ',$t,' Value="',$count,'">',$count,'</option>';
			$count++;
		}
	}
	
	echo"</select></td></tr>";
	
	
	if ($ref!=1)
	{
		$q = "SELECT * FROM $tbl_lg WHERE leagueId=$liga";
		$qe = mysql_query($q);
		
		echo '<tr>
				<td>Gruppe:</td>
				<td><select name="stage" Size="1">';
		
		$scount = mysql_num_rows($qe);
		
		if ($scount>0)
		{
			while ($row = mysql_fetch_object($qe))
				{
					$id=$row->id;
					$t="";
					if ($id==$stage)
					{
						$t="selected";
					}
					echo '<Option ',$t,' Value="',$id,'">' ,$row->groupName, '</option>';
				}
		}
		else
		{
			echo '<Option selected Value="0">Keine</option>';
		}
		echo"</select></td></tr>";
	}
	
	
	if ($ref!=1)
	{
		$abfrage = "SELECT t.id, t.name FROM $tbl_teams t, $tbl_lt lt WHERE lt.leagueId=$liga AND lt.teamId=t.id ORDER BY name"; 
	}
	else
	{
		$abfrage = "SELECT t.id, t.name FROM $tbl_teams t, $tbl_gt gt WHERE gt.groupId=$stage AND gt.teamId=t.id ORDER BY name";
	}
	
	
	$ergebnis = mysql_query($abfrage);
	
	echo '<tr>
			<td>Heim:</td>
			<td><select name="homeTeam" Size="1">';
	
	while ($row = mysql_fetch_object($ergebnis))
		{
			$id=$row->id;
			$t="";
			if ($id==$homeT)
			{
				$t="selected";
			}
			echo '<Option ',$t,' Value="',$id,'">' ,$row->name, '</option>';
		}
		
	echo"</select></td></tr>";
	

	$ergebnis = mysql_query($abfrage);
	
	echo '<tr>
			<td>Gast:</td>
			<td><select name="guestTeam" Size="1">';
	
	
	while ($row = mysql_fetch_object($ergebnis))
		{
			$id=$row->id;
			$t="";
			if ($id==$guestT)
			{
				$t="selected";
			}
			echo '<Option ',$t,' Value="',$id,'">' ,$row->name, '</option>';
		}
		
	echo"</select></td></tr>";
	
	
	$nf="";
	$fr="";
	$wa="";
	$be="";
	
	if ($free==0)
	{
		$nf="selected";
	}
	else
		{
			if ($free==1)
			{
				$fr="selected";
			}
			else
				{
					if ($free==2)
					{
						$wa="selected";
					}
					else
						{
							$be="selected";
						}
				}
		}
	
	echo " 		<tr>
					<td>Status:</td>
					<td>
						<select name='free'>
							<option ",$nf," value='0'>Nicht freigegeben</option>
							<option ",$fr," value='1'>Freigegeben</option>
							<option ",$wa," value='2'>Warten auf Bestätigung</option>
							<option ",$be," value='3'>Bestätigt</option>
						</select>
					</td>
				</tr>
			</table>";
	
	echo '	<input type="text" name="liga" value="',$liga,'" hidden>';





echo '	<br>
		<input type="submit" value="Bearbeiten" class="button anlegen">
		</form>';

	if ($ref!=1)
	{
		$t="ligaspiele.php?liga=$liga&matchday=$matchday";
	}
	else
	{
		$t="gruppenspiele.php?gruppe=$stage&matchday=$matchday";
	}
echo "<center><a href='",$t,"' class='button zurueck'>Zurück</a></center>";
}
?>
</body>
</html>

